package com.chunwei.advert.controller;

import com.chunwei.advert.common.utils.PageUtils;
import com.chunwei.advert.common.utils.R;
import com.chunwei.advert.entity.AdvertEntity;
import com.chunwei.advert.service.AdvertService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.Map;


@RestController
@RequestMapping("advert")
@CrossOrigin
public class AdvertController
{

    @Autowired
    private AdvertService advertService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params)
    {
        PageUtils page = advertService.queryPage(params);

        return R.data(page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    public R info(@PathVariable("id") Long id)
    {
        AdvertEntity advert = advertService.getById(id);

        return R.data(advert);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody AdvertEntity advert)
    {
        advertService.save(advert);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody AdvertEntity advert)
    {
        advertService.updateById(advert);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Long[] ids)
    {
        advertService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }
}

